﻿using System.Text.RegularExpressions;

namespace CnSharp.SSMS.AddIn.Util
{
    public class ObjectNodeContextRegex
    {
        public static readonly Regex DbRegex =
            new Regex(@"^Server\[@Name='(?<Server>[^']*)'\]/Database\[@Name='(?<Database>[^']*)'\]$");

        public static readonly Regex DbRegexStart =
          new Regex(@"^Server\[@Name='(?<Server>[^']*)'\]/Database\[@Name='(?<Database>[^']*)'\]");


        public static readonly Regex SpFolderRegex =
            new Regex(
                @"^Server\[@Name='(?<Server>[^']*)'\]/Database\[@Name='(?<Database>[^']*)'\]/Folder\[@Name='StoredProcedures' and @Type='StoredProcedure'\]");

        public static readonly Regex SpRegex =
            new Regex(
                @"Server\[[^\]]*\]/Database\[@Name='(?<Database>[^']*)'\]/StoredProcedure\[@Name='(?<StoredProcedure>[^']*)' and @Schema='(?<Schema>[^']*)'\]$");

        public static readonly Regex TableFolderRegex =
            new Regex(
                @"^Server\[@Name='(?<Server>[^']*)'\]/Database\[@Name='(?<Database>[^']*)'\]/Folder\[@Name='UserTables' and @Type='Table'\]");

        public static readonly Regex TableRegex =
            new Regex(
                @"^Server\[@Name='(?<Server>[^\]]*)'\]/Database\[@Name='(?<Database>[^']*)'\]/Table\[@Name='(?<Table>[^']*)' and @Schema='(?<Schema>[^']*)'\]$");

        public static readonly Regex ViewFolderRegex =
            new Regex(@"^Server\[@Name='(?<Server>[^']*)'\]/Database\[@Name='(?<Database>[^']*)'\]/Folder\[@Name='Views' and @Type='View'\]");

        public static readonly Regex ViewRegex =
            new Regex(
                @"^Server\[@Name='(?<Server>[^']*)'\]/Database\[@Name='(?<Database>[^']*)'\]/View\[@Name='(?<View>[^']*)' and @Schema='(?<Schema>[^']*)'\]$");
    }
}

/*notes
 
Server[@Name='JEREMYCHIN0D6C']

Server[@Name='JEREMYCHIN0D6C']/Database[@Name='CnSharp']

Server[@Name='JEREMYCHIN0D6C']/Database[@Name='CnSharp']/Folder[@Name='UserTables' and @Type='Table']

Server[@Name='JEREMYCHIN0D6C']/Database[@Name='CnSharp']/Table[@Name='Country' and @Schema='dbo']

Server[@Name='JEREMYCHIN0D6C']/Database[@Name='CnSharp']/Folder[@Name='Views' and @Type='View']

Server[@Name='JEREMYCHIN0D6C']/Database[@Name='CnSharp']/View[@Name='V_ActivityOrder' and @Schema='dbo']

Server[@Name='JEREMYCHIN0D6C']/Database[@Name='CnSharp']/Folder[@Name='StoredProcedures' and @Type='StoredProcedure']

Server[@Name='JEREMYCHIN0D6C']/Database[@Name='CnSharp']/StoredProcedure[@Name='PROCE_PAGECHANGE' and @Schema='dbo']

Server[@Name='JEREMYCHIN0D6C']/Database[@Name='CnSharp']/Folder[@Name='UserProgrammability' and @Type='StoredProcedure;UserDefinedFunction;UserDefinedAggregate;DdlTrigger;SqlAssembly;UserDefinedType;XmlSchemaCollection;Rule;Sequence;Default;PlanGuide;UserDefinedDataType;UserDefinedTableType']


Server[@Name='JEREMYCHIN0D6C']/Database[@Name='CnSharp']/Folder[@Name='UsrDbFunctions' and @Type='UserDefinedFunction;UserDefinedAggregate']
Server[@Name='JEREMYCHIN0D6C']/Database[@Name='CnSharp']/Folder[@Name='Table-valuedFunctions' and @Type='UserDefinedFunction[(@FunctionType=3 or @FunctionType=2)]']
Server[@Name='JEREMYCHIN0D6C']/Database[@Name='CnSharp']/Folder[@Name='Scalar-valuedFunctions' and @Type='UserDefinedFunction[@FunctionType=1]']
Server[@Name='JEREMYCHIN0D6C']/Database[@Name='CnSharp']/Folder[@Name='AggregateFunctions' and @Type='UserDefinedAggregate']

*/